package com.bjdd.jdy.ui.resetPwd;

import com.bjdd.jdy.util.SignUtils;
import com.bjdd.jdy.util.StringUtils;
import com.bjdd.jdy.util.T;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

/**
 * Created by Administrator on 2017/4/12.
 */

public class ResetPwdPresenter extends ResetPwdContract.Presenter {
    @Override
    public void commit(String code, String phone, String pwd) {
        String timestamp = SignUtils.getTime();
        Map<String,String> map = new HashMap<>();
        map.put("mobile",phone);
        map.put("code",code);
        pwd = StringUtils.MD5(pwd);
        map.put("pwd",pwd);
        map.put("timestamp",timestamp);
        String sign = SignUtils.getSignature(map);
        showLoadingDialog(false);
        rxManager.add(model.getResultModel(phone,pwd,code,timestamp,sign)
                .subscribe(result -> {
                    hideLoadingDialog();
                    if (!result.isError()){
                        view.resetSuccess();
                    }else {
                        T.show(result.getData());
                    }
                },e -> {
                    hideLoadingDialog();
                    T.show("修改失败");
                }));
    }

    @Override
    public void getCode(String phone) {
        String timestamp = SignUtils.getTime();
        Map<String,String> map = new HashMap<>();
        map.put("mobile",phone);
        map.put("timestamp",timestamp);
        String sign = SignUtils.getSignature(map);
        showLoadingDialog(false);
        rxManager.add(model.getCodeModel(phone,timestamp,sign)
                .subscribe(result -> {
                   hideLoadingDialog();
                    T.show(result.getMsg());
                },e -> {
                    hideLoadingDialog();
                }));

    }

    @Override
    public void onStart() {

    }
}
